import {
  getUserList,
  addOneUser,
  updateOneUser,
  getUserByID,
  deleteUserByIDs
} from '@/api/user'

const userManagement = {
  state: {
  },

  mutations: {
  },

  actions: {
    // 查询用户列表
    getUserList({ commit }, condition) {
      return new Promise((resolve, reject) => {
        getUserList(condition).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    // 新增一个用户
    addOneUser({ commit }, data) {
      return new Promise((resolve, reject) => {
        addOneUser(data).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    // 根据id查询用户详情
    getUserByID({ commit }, id) {
      return new Promise((resolve, reject) => {
        getUserByID(id).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    // 更新一个用户
    updateOneUser({ commit }, data) {
      return new Promise((resolve, reject) => {
        updateOneUser(data).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    // 根据id批量删除用户
    deleteUserByIDs({ commit }, data) {
      return new Promise((resolve, reject) => {
        deleteUserByIDs(data).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    }
  }
}

export default userManagement

